import { message } from 'antd';
import { fetchMembersList,fetchShopList,fetchCardList,getClassInfo ,getCourseBaseInfo} from './service';

const Model = {
  namespace: 'cubeSignIn',
  state: {
    member:null,
    membersList:[],
    shopList:[],
    cardList:[],
    classInfoList:[],
    courseList:[]
  },
  effects: {
    *fetchMembersList({ payload }, { call,put }) {
      let result=yield call(fetchMembersList, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            membersList:result.data          }
        });
      }else{
        message.error(result.message);
      }
    },
    *fetchShopList({ payload }, { call,put }) {
      let result=yield call(fetchShopList, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            shopList:result.data         
           }
        });
      }else{
        message.error(result.message);
      }
    },
    *fetchCardList({ payload }, { call,put }) {
      let result=yield call(fetchCardList, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            cardList:result.data         
           }
        });
      }else{
        message.error(result.message);
      }
    },
    *getClassInfo({ payload }, { call,put }) {
      let result=yield call(getClassInfo, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            classInfoList:result.data         
           }
        });
      }else{
        message.error(result.message);
      }
    },
    *getCourseBaseInfo({ payload }, { call,put }) {
      let result=yield call(getCourseBaseInfo, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            courseList:result.data         
           }
        });
      }else{
        message.error(result.message);
      }
    },
  },
  reducers: {
    common(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
export default Model;
